﻿
@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<style>
    .form .formValue input.form-control {
        height: 34px;
        line-height: 34px;
    }

    .form-control {
        padding: 0px;
    }
    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }
    .Table {
        width: 100%;
        margin: 0px;
        padding: 0px;
        border-collapse: collapse;
        border-width: 3px 1px 1px;
        table-layout: fixed;
    }
</style>
<script>
    var resultData = {};
    var F_Id = $.request("F_Id");
    var contactId = $.request("contactId"); 
    var F_OrderId = $.request("F_OrderId");
    $(function () {
        GetInit();
        $("#F_ActivityCityId").select2({ multiple: true });
        $("#F_SiteType").select2({ multiple: true });
        initEntity();
        var F_ClientId = $.request("F_ClientId");
        var F_ProjectId = $.request("F_ProjectId");
        var F_BrandId = $.request("F_BrandId");        
        $("#hd_F_Contact").val(contactId);
        $("#hd_F_BrandId").val(F_BrandId);
        $("#hd_F_ProjectId").val(F_ProjectId);
        gridList(F_ClientId, F_Id);
        ProjectChange(F_ClientId);
        BrandsChange(F_ClientId);
        ContactsChange(F_ClientId);
        if ($.request("ishow") == "1") {
            $("#isF_Contact").hide();
            $("#F_Phone").hide();
            $("#F_Mail").hide();
            $("#F_Telephone").hide();
            $("#F_DepartmentId").hide();
            $("#F_PositionId").hide();
        }
    });

    function initEntity() {
        $.ajax({
            url: "/ClientManager/DemandInfos/GetMemandEntity?F_Id=" + F_Id +"",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data != null) {
                    $("#F_ClientType").val(data["F_ClientType"]);
                    $("#hd_ClientName").val(data["F_ClientId"]);                  

                    $("#F_ClientName").val(data["F_ClientName"]);                   
                    $("#F_ClientLevel").val(data["F_ClientLevel"]);
                    if (data["F_CityId"] != null) {
                        $("#F_CityId").val(data["F_CityId"].split(',')).trigger('change');
                    }                    
                    ChangeCityData();
                    if (data["F_AreaId"] != null) {
                        $("#F_AreaId").val(data["F_AreaId"].split(',')).trigger('change');
                    }
                    
                    $("#F_Address").val(data["F_Address"]);
                    $("#F_MappingId").val(data["MappingName"]);
                    $("#hd_F_MappingId").val(data["MappingId"]);
                    $("#F_ProjectId").val(data["F_ProjectName"]);
                    $("#hd_ProjectId").val(data["ProjectId"]);
                    $("#F_BrandId").val(data["F_BrandName"]);
                    $("#hd_F_BrandId").val(data["F_BrandId"]);
                    $("#F_Contact").val(data["F_Contact"]);
                    $("#F_DepartmentId").val(data["F_DepartmentId"]);
                    $("#F_PositionId").val(data["F_PositionId"]);
                    $("#F_Phone").val(data["F_Phone"]);
                    $("#F_Telephone").val(data["F_Telephone"]);
                    $("#F_Mail").val(data["F_Mail"]);
                    $("#F_ActivityTheme").val(data["F_ActivityTheme"]);
                    $("#F_ActivityType").val(data["F_ActivityType"]);
                    $("#F_DemandCash").val(data["F_DemandCash"]);
                    $("#F_ActivityStartDate").val(data["F_ActivityStartDate"]);
                    $("#F_ActivityEndDate").val(data["F_ActivityEndDate"]);
                    $("#F_BuildDate").val(data["F_BuildDate"]);
                    if (data["F_ActivityCityId"] != null) {
                        $("#F_ActivityCityId").val(data["F_ActivityCityId"].split(',')).trigger('change');
                    }

                    $("#F_ZkIndustryId").val(data["F_ZkIndustryId"]);

                    if (data["F_SiteType"] != null) {
                        $("#F_SiteType").val(data["F_SiteType"].split(',')).trigger('change');
                    }
                    
                    $("#F_SiteArea").val(data["F_SiteArea"]);
                    $("#F_Height").val(data["F_Height"]);
                    $("#F_Intention").val(data["F_Intention"]);                    
                    $("#F_Note").val(data["F_Note"]);
                    
                    $("#F_Mark").val(data["F_Mark"]);
                    $("#F_Source").val(data["F_Source"]);
                    $("#F_PersionNumber").val(data["F_PersionNumber"]);
                    $("input[name='F_State'][value=" + data["F_State"] + "]").attr("checked", true); 
                    $("input[name='F_Sex'][value=" + data["F_Sex"] + "]").attr("checked", true); 
                    $("input[name='F_CloseReason'][value=" + data["F_CloseReason"] + "]").attr("checked", true);

                    if (data["F_State"] != "2") {
                        $("#tr_reason").hide();
                    } else {
                        $("#tr_reason").show();
                    }

                    if (data["F_ClientType"] == "1") {
                        //$("#F_CompanyType").val(data["F_CompanyType"]);                       
                        $("#F_MappingId").attr("disabled", "disabled");
                        $("#F_MappingId").css("background-color", "#ddd");

                        $("#F_ZkIndustryId").attr("disabled", "disabled");
                        $("#F_ZkIndustryId").css("background-color", "#ddd");  

                        $("#F_IndustryId").val(data["F_IndustryId"]);
                    } else {
                        $("#F_IndustryId").attr("disabled", "disabled");
                        $("#F_IndustryId").css("background-color", "#ddd");                      
                        $("#F_MappingId").removeAttr("disabled");
                        $("#F_MappingId").css("background-color", "#fff"); 
                       
                    }
                }
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function InitControl() {
        var F_ClientType = resultData.F_ClientType;
        for (var i = 0; i < F_ClientType.length; i++) {
            $("#F_ClientType").append("<option value='" + F_ClientType[i].F_ItemCode + "'>" + F_ClientType[i].F_ItemName + "</option>");
        }

        var F_CompanyType = resultData.F_CompanyType;
        for (var i = 0; i < F_CompanyType.length; i++) {
            $("#F_CompanyType").append("<option value='" + F_CompanyType[i].F_ItemCode + "'>" + F_CompanyType[i].F_ItemName + "</option>");
        }

        var F_ClientLevel = resultData.F_ClientLevel;
        for (var i = 0; i < F_ClientLevel.length; i++) {
            $("#F_ClientLevel").append("<option value='" + F_ClientLevel[i].F_ItemCode + "'>" + F_ClientLevel[i].F_ItemName + "</option>");
        }

        var F_IndustryId = resultData.F_IndustryId;
        for (var i = 0; i < F_IndustryId.length; i++) {
            $("#F_IndustryId").append("<option value='" + F_IndustryId[i].F_ItemCode + "'>" + F_IndustryId[i].F_ItemName + "</option>");
            $("#F_ZkIndustryId").append("<option value='" + F_IndustryId[i].F_ItemCode + "'>" + F_IndustryId[i].F_ItemName + "</option>");
        }

        var F_DepartmentId = resultData.F_DepartmentId;
        for (var i = 0; i < F_DepartmentId.length; i++) {
            $("#F_DepartmentId").append("<option value='" + F_DepartmentId[i].F_ItemCode + "'>" + F_DepartmentId[i].F_ItemName + "</option>");
        }

        var F_PositionId = resultData.F_PositionId;
        for (var i = 0; i < F_PositionId.length; i++) {
            $("#F_PositionId").append("<option value='" + F_PositionId[i].F_ItemCode + "'>" + F_PositionId[i].F_ItemName + "</option>");
        }

        var F_ActivityType = resultData.F_ActivityType;
        var First_ActivityType = resultData.First_ActivityType;
        var strHtml = "";
        for (var j = 0; j < First_ActivityType.length; j++) {
            strHtml += "<option style=\"font-weight:bold;\" label='" + First_ActivityType[j]["F_ItemName"] + "'>";
            for (var i = 0; i < F_ActivityType.length; i++) {
                if (First_ActivityType[j].F_ItemCode == F_ActivityType[i].F_Description) {
                    strHtml += "<option value='" + F_ActivityType[i].F_ItemCode + "'>" + "&nbsp;&nbsp;&nbsp;&nbsp;" + F_ActivityType[i].F_ItemName + "</option>";
                }
            }
            strHtml += "</option>"; 
        }
        $("#F_ActivityType").append(strHtml);

        //var F_ActivityCityId = resultData.F_ActivityCityId;
        //for (var i = 0; i < F_ActivityCityId.length; i++) {
        //    $("#F_ActivityCityId").append("<option value='" + F_ActivityCityId[i].F_ItemCode + "'>" + F_ActivityCityId[i].F_ItemName + "</option>");
        //}
        $("#F_ActivityCityId").bindSelect({
            url: "/ClientManager/ClientInfos/GetAllCitys",
            search: true,
            id: "F_EnCode",
            text: "F_FullName"
        });

        var F_SiteType = resultData.F_SiteType;
        for (var i = 0; i < F_SiteType.length; i++) {
            $("#F_SiteType").append("<option value='" + F_SiteType[i].F_ItemCode + "'>" + F_SiteType[i].F_ItemName + "</option>");
        }

        $("#F_CityId").bindSelect({
            url: "/ClientManager/ClientInfos/GetAllCitys",
            search: true,
            id: "F_EnCode",
            text: "F_FullName"
        });        

        //var F_CityId = resultData.F_CityId;
        //for (var i = 0; i < F_CityId.length; i++) {
        //    $("#F_CityId").append("<option value='" + F_CityId[i].F_Id + "'>" + F_CityId[i].F_ItemName + "</option>");
        //}

        //var F_AreaId = resultData.F_AreaId;
        //for (var i = 0; i < F_AreaId.length; i++) {
        //    $("#F_AreaId").append("<option value='" + F_AreaId[i].F_ItemCode + "'>" + F_AreaId[i].F_ItemName + "</option>");
        //}

        var Clients = [];
        var SiteClients = resultData.SiteClients;
        for (var i = 0; i < SiteClients.length; i++) {
            Clients.push({ value: SiteClients[i].F_ClientName, data: SiteClients[i].F_Id });
        }

        $("#F_ClientName").autocomplete({
            lookup: Clients,
            onSelect: function (suggestion) {
                $("#hd_ClientName").val(suggestion.data);
                for (var i = 0; i < resultData.SiteClients.length; i++) {
                    if (suggestion.data == resultData.SiteClients[i].F_Id) {
                        $("#F_CompanyType").val(resultData.SiteClients[i].F_CompanyType);
                        $("#F_ClientLevel").val(resultData.SiteClients[i].F_ClientLevel);
                        $("#F_CityId").val(resultData.SiteClients[i].F_CityId);
                        ChangeCityData();
                        $("#F_Address").val(resultData.SiteClients[i].F_Address);
                        $("#F_IndustryId").val(resultData.SiteClients[i].F_IndustryId);
                    }
                }
                ProjectChange(suggestion.data);
                BrandsChange(suggestion.data);               
                ContactsChange(suggestion.data);
                ReloadGridListRecord(suggestion.data);
            }
        });

        $("#F_MappingId").autocomplete({
            lookup: Clients,
            onSelect: function (suggestion) {
                $("#hd_F_MappingId").val(suggestion.data);
            }
        });
    }

    function ContactsChange(f_fartherId) {
        var contacts = [];
        var sitecontacts = resultData.Contacts;
        for (var i = 0; i < sitecontacts.length; i++) {
            if (sitecontacts[i].F_ClientId == f_fartherId) {
                contacts.push({ value: sitecontacts[i].F_Contact, data: sitecontacts[i].F_Id });
            }
        }
        $("#F_Contact").autocomplete({
            lookup: contacts,
            onSelect: function (suggestion) {
                $("#hd_F_Contact").val(suggestion.data);
                ContactInfo(suggestion.data);
            }
        });
    }

    function ContactInfo(contactId) {
        $.ajax({
            url: "/ClientManager/ClientInfos/GetContactInfo?F_ContactId=" + contactId,
            dataType: "json",
            async: false,
            success: function (data) {
                if (data != null) {
                    $("#F_DepartmentId").val(data["F_DepartmentId"]);
                    $("#F_PositionId").val(data["F_PositionId"]);
                    $("#F_Phone").val(data["F_Phone"]);
                    $("#F_Telephone").val(data["F_Telephone"]);
                    $("#F_Mail").val(data["F_Mail"]);
                    $("input[name='F_Sex'][value=" + data["F_Sex"] + "]").attr("checked", true);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { }
        });
    }

    function BrandsChange(f_fartherId) {
        var Brands = [];
        var siteBrands = resultData.Brands;
        for (var i = 0; i < siteBrands.length; i++) {
            if (siteBrands[i].F_ClientId == f_fartherId) {
                Brands.push({ value: siteBrands[i].F_BrandName, data: siteBrands[i].F_Id });
            }
        }

        $("#F_BrandId").autocomplete({
            lookup: Brands,
            onSelect: function (suggestion) {
                $("#hd_F_BrandId").val(suggestion.data);
            }
        });
    }

    function ProjectChange(f_fartherId) {
        var Projects = [];
        var siteProjects = resultData.Projects;
        for (var i = 0; i < siteProjects.length; i++) {
            if (siteProjects[i].F_ClientId == f_fartherId) {
                Projects.push({ value: siteProjects[i].F_ProjectName, data: siteProjects[i].F_Id });
            }
        }

        $("#F_ProjectId").autocomplete({
            lookup: Projects,
            onSelect: function (suggestion) {
                $("#hd_F_ProjectId").val(suggestion.data);               
            }
        });
    }

    function ReloadGridListRecord(F_ClientId) {
        var $gridList = $("#gridList");       
        $gridList.jqGrid('setGridParam', {
            postData: { F_ClientId: F_ClientId },
        }).trigger('reloadGrid');
    }

    function gridList(F_ClientId, F_Id) {
        var $gridList = $("#gridList");
        var queryJson = {};
        $gridList.dataGrid({
            url: "/ClientManager/DemandInfos/GetClientOrderHistoryList",
            postData: { F_ClientId: F_ClientId, F_Id: F_Id },
            height: 300,
            colModel: [                
                { label: '公司名称', name: 'F_ClientName', align: 'left' },
                {
                    label: '品牌项目组', name: 'F_ProjectName', align: 'left'
                },
                {
                    label: '活动主题', name: 'F_ActivityTheme', align: 'left'
                },
                {
                    label: '活动类型', name: 'F_ActivityType', align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, "F_ActivityType");
                    }
                },
                { label: '预算金额(元)', name: 'F_DemandCash', align: 'left' },
                { label: '活动开始日期', name: 'F_ActivityStartDate', align: 'left' },
                {
                    label: '活动结束日期', name: 'F_ActivityEndDate', align: 'left'
                },
                {
                    label: '活动城市', name: 'F_ActivityCityId', align: 'left', formatter: function (cellvalue) {
                        return GetDictionaries(cellvalue, "F_ActivityCityId");
                    }
                },                
                { label: '联系人', name: 'F_Contact', align: 'left' },
                { label: '联系电话', name: 'F_Phone', align: 'left' },
                {
                    label: '需求单状态', name: 'F_State', formatter: function (cellvalue) {
                        if (cellvalue == "0") {
                            return '草稿';
                        }
                        else if (cellvalue == "1") {
                            return '转订单';
                        }
                        else if (cellvalue == "2") {
                            return '无效需求';
                        } else {
                            return '';
                        }
                    }
                },                
                {
                    label: '订单状态', name: 'orderState', formatter: function (cellvalue) {
                        if (cellvalue == "0") {
                            return '无效';
                        }
                        else if (cellvalue == "1") {
                            return '有效';
                        } else {
                            return '';
                        }
                    }},
                { label: '需求创建时间', name: 'F_CreatorTime' },
                { label: '', name: 'DemandId', hidden: true },               
                { label: '', name: 'F_Id', hidden: true }
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            rowNum: 10,
            rowList: [10, 20,30],
            ondblClickRow: function (rowid, iRow, iCol, e) {
                Infos();
            },
            loadComplete: function (data) {

            }
        });
    }

    function Infos() {
        var rowobj = $("#gridList").jqGridRowValue();
        $.modalOpen({
            id: "hisForm",
            title: "历史明细",
            url: "/ClientManager/DemandInfos/Infos?F_Id=" + rowobj["DemandId"] +"&contactId=",
            width: "1200px",
            height: "950px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            },
            btn: null
        });
    }

    function GetDictionaries(value, type) {
       if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_CityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_CityId[i].F_EnCode) {
                            strHtml += resultData.F_CityId[i].F_FullName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_CityId[i].F_EnCode) {
                            strHtml += resultData.F_CityId[i].F_FullName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }    
    
    function ChangeCityData() {
        var id = $("#F_CityId").val();
        $("#F_AreaId").empty();
        var F_AreaId = resultData.F_AreaId;
        for (var i = 0; i < F_AreaId.length; i++) {
            if (F_AreaId[i].F_ParentId == id) {
                $("#F_AreaId").append("<option value='" + F_AreaId[i].F_EnCode + "'>" + F_AreaId[i].F_FullName + "</option>");
            }
        }
    }

    function GetInit() {
        resultData = getCache("DEMAND_FORM");
        if (!resultData || resultData.length <= 0) {
            $.ajax({
                url: "/ClientManager/DemandInfos/GetItemListJson",
                dataType: "json",
                async: false,
                success: function (data) {
                    resultData = data;
                    InitControl();
                    setCache("DEMAND_FORM", data);
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            });
        } else {
            InitControl();
        }
    }

    function ChangeClientType() {
        var F_ClientType = $("#F_ClientType").val();
        if (F_ClientType == "1") {
            $("#F_CompanyType").attr("disabled", "disabled");
            $("#F_CompanyType").css("background-color", "#ddd");
            $("#F_MappingId").attr("disabled", "disabled");
            $("#F_MappingId").css("background-color", "#ddd");

            $("#F_IndustryId").removeAttr("disabled");
            $("#F_IndustryId").css("background-color", "#fff");


        } else {
            $("#F_IndustryId").attr("disabled", "disabled");
            $("#F_IndustryId").css("background-color", "#ddd");

            $("#F_CompanyType").removeAttr("disabled");
            $("#F_CompanyType").css("background-color", "#fff");
            $("#F_MappingId").removeAttr("disabled");
            $("#F_MappingId").css("background-color", "#fff");
        }
    }

    function submitForm() {
        var F_State = $("input[name='F_State']:checked").val();
        if (F_State != "2") {
            if (!$('#projectForm').formValid()) {
                return false;
            }
        }
        
        var F_ClientType = $("#F_ClientType").val();
        var hd_ClientName = $("#hd_ClientName").val();
        var F_ClientName = $("#F_ClientName").val();
        var F_ClientId = hd_ClientName;        

        var F_ClientLevel = $("#F_ClientLevel").val();
        var F_CityId = $("#F_CityId").val();
        var F_AreaId = $("#F_AreaId").val();

        var F_Address = $("#F_Address").val();
        var F_IndustryId = $("#F_IndustryId").val();

        var F_Source = $("#F_Source").val();
        var F_ActivityTheme = $("#F_ActivityTheme").val();
        var F_ActivityType = $("#F_ActivityType").val();
        var F_DemandCash = $("#F_DemandCash").val();

        var F_ActivityStartDate = $("#F_ActivityStartDate").val();
        var F_ActivityEndDate = $("#F_ActivityEndDate").val();

        var F_ACityIdList = $("#F_ActivityCityId").select2("data");
        var F_ActivityCityId = "";
        for (var i = 0; i < F_ACityIdList.length; i++) {
            if (i == F_ACityIdList.length - 1) {
                F_ActivityCityId += F_ACityIdList[i].id;
            } else {
                F_ActivityCityId += F_ACityIdList[i].id + ",";
            }
        }

        var F_SiteType1 = $("#F_SiteType").select2("data");
        var F_SiteType = "";
        for (var i = 0; i < F_SiteType1.length; i++) {
            if (i == F_SiteType1.length - 1) {
                F_SiteType += F_SiteType1[i].id;
            } else {
                F_SiteType += F_SiteType1[i].id + ",";
            }
        }

        var F_PersionNumber = $("#F_PersionNumber").val();
        var F_SiteArea = $("#F_SiteArea").val();
        var F_Height = $("#F_Height").val();
        var F_Note = $("#F_Note").val();
        var F_Mark = $("#F_Mark").val();
        var F_Intention = $("#F_Intention").val();
        

        var hd_F_MappingId = $("#hd_F_MappingId").val();        
        var F_MappingId = "";
        var F_ClientType2 = $("#F_ClientType").val();
        if (F_ClientType2 == "1") {
            F_MappingId = $("#hd_F_MappingId").val();
        } else {
            F_MappingId = hd_F_MappingId;
            var F_MappingName = $("#F_MappingId").val();
        }

        var F_BrandId = $("#hd_F_BrandId").val();
        var F_BrandName = $("#F_BrandId").val();        

        var F_ProjectId = $("#hd_F_ProjectId").val();
        var F_ProjectName = $("#F_ProjectId").val();       

        var F_ContactId = $("#hd_F_Contact").val();
        var F_Contact = $("#F_Contact").val();       

        var F_DepartmentId = $("#F_DepartmentId").val();
        var F_PositionId = $("#F_PositionId").val();
        var F_Sex = $("input[name='F_Sex']:checked").val();

        var F_Phone = $("#F_Phone").val();
        var F_Telephone = $("#F_Telephone").val();
        var F_Mail = $("#F_Mail").val();
        var F_BuildDate = $("#F_BuildDate").val();
        var F_ZkIndustryId = $("#F_ZkIndustryId").val();

        var F_CloseReason = $("input[name='F_CloseReason']:checked").val();
        if (F_State == "2") {
            if (F_CloseReason == undefined) {
                $.modalAlert("请选择关闭理由！", "warning");
                return;
            }
        }        

        $.ajax({
            url: "/ClientManager/DemandInfos/SubmitForm",
            data: {
                F_ClientType: F_ClientType, F_ClientId: F_ClientId, F_ClientName: F_ClientName, F_ClientLevel: F_ClientLevel, F_CityId: F_CityId,
                F_AreaId: F_AreaId, F_Address: F_Address, F_IndustryId: F_IndustryId, F_Source: F_Source,
                F_ActivityTheme: F_ActivityTheme, F_ActivityType: F_ActivityType, F_DemandCash: F_DemandCash, F_ActivityStartDate: F_ActivityStartDate,
                F_ActivityEndDate: F_ActivityEndDate, F_ActivityCityId: F_ActivityCityId, F_SiteType: F_SiteType, F_SiteArea: F_SiteArea, F_PersionNumber: F_PersionNumber,
                F_Height: F_Height, F_Note: F_Note, F_Intention: F_Intention, F_MappingId: F_MappingId, F_MappingName: F_MappingName, F_BrandId: F_BrandId, F_BrandName: F_BrandName,
                F_ProjectId: F_ProjectId, F_ProjectName: F_ProjectName, F_ContactId: F_ContactId, F_Contact: F_Contact, F_DepartmentId: F_DepartmentId, F_PositionId: F_PositionId,
                F_Sex: F_Sex, F_Phone: F_Phone, F_Telephone: F_Telephone, F_Mail: F_Mail,
                F_Mark: F_Mark, F_State: F_State, F_Id: F_Id, F_OrderId: F_OrderId, F_CloseReason: F_CloseReason, F_BuildDate: F_BuildDate, F_ZkIndustryId: F_ZkIndustryId
            },
            dataType: "json",
            type: 'POST',
            async: false,
            success: function (data) {
                if (data != null) {
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                    if (data["F_State"] == 0) {
                        $.modalFrameClose('editForm');
                    } else {
                        layer.confirm('需要跳转到销售分配窗口吗？', {
                            btn: ['是', '否']
                        }
                            , function () {
                                if (F_Source == "0" || F_Source == "2" || F_Source == "3" || F_Source == "4") {
                                    $.modalOpen({
                                        id: "Share",
                                        title: "分配需求单",
                                        url: "/ClientManager/DemandInfos/Share?F_Id=" + F_Id + "",
                                        width: "1200px",
                                        height: "900px",
                                        callBack: function (iframeId) {
                                            top.frames[iframeId].submitForm();
                                            $.modalFrameClose('editForm');
                                        }
                                    });
                                } else {
                                    $.addTab({
                                        href: '/OrderFlowManage/ClientOrder/Details?pageType=all&orderid=' + data["F_Id"] + '&type=' + data["F_OrderState"],
                                        text: '需求流转',
                                        id: data["F_Id"],
                                        index: 999
                                    });
                                    $.modalFrameClose('editForm');
                                }
                            },
                            function () {
                                $.modalFrameClose('editForm');
                            }
                        );
                    }                    
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { }
        });
        //$.submitForm({
        //    url: "/ClientManager/DemandInfos/SubmitForm",
        //    param: {
        //        F_ClientType: F_ClientType, F_ClientId: F_ClientName, F_ClientLevel: F_ClientLevel, F_CityId: F_CityId,
        //        F_AreaId: F_AreaId, F_Address: F_Address, F_IndustryId: F_IndustryId, F_Source: F_Source,
        //        F_ActivityTheme: F_ActivityTheme, F_ActivityType: F_ActivityType, F_DemandCash: F_DemandCash, F_ActivityStartDate: F_ActivityStartDate,
        //        F_ActivityEndDate: F_ActivityEndDate, F_ActivityCityId: F_ActivityCityId, F_SiteType: F_SiteType, F_SiteArea: F_SiteArea, F_PersionNumber: F_PersionNumber,
        //        F_Height: F_Height, F_Note: F_Note, F_MappingId: F_MappingId, F_BrandId: F_BrandId,               
        //        F_ProjectId: F_ProjectId, F_Contact: F_Contact, F_DepartmentId: F_DepartmentId, F_PositionId: F_PositionId,
        //        F_Sex: F_Sex, F_Phone: F_Phone, F_Telephone: F_Telephone,F_Mail: F_Mail,                  
        //        F_Mark: F_Mark, F_State: F_State, F_Id: F_Id, F_OrderId: F_OrderId, F_CloseReason: F_CloseReason, F_BuildDate: F_BuildDate, F_ZkIndustryId: F_ZkIndustryId
        //    },
        //    success: function () {
        //        $.currentWindow().$("#gridList").trigger("reloadGrid");
        //    }
        //});
    }

    function ChangeFState() {
        var F_State = $("input[name='F_State']:checked").val();
        if (F_State == "2") {
            $("#tr_reason").show();
        }
    }
</script>
<div id="ProjectsDetail">
    <form id="projectForm">
        <table class="form">
            <tr>
                <td colspan="6" class="interval">公司基本资料</td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">客户类型</td>
                            <td class="formValue">
                                <select id="F_ClientType" name="F_ClientType" class="form-control" onchange="ChangeClientType()">
                                    <option value="">==请选择客户类型==</option>
                                </select>
                            </td>
                            <td class="formTitle">客户名称<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <div class="input-group" style="width:100%;">
                                    <input type="text" id="F_ClientName" name="F_ClientName" class="form-control" placeholder="请输入客户名称" />
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search required"></i></span>
                                    <input type="hidden" name="hd_ClientName" id="hd_ClientName" value="" />
                                </div>
                            </td>
                            <td class="formTitle">客户等级</td>
                            <td class="formValue">
                                <select id="F_ClientLevel" name="F_ClientLevel required" class="form-control">
                                    <option value="">==请选择客户等级==</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            
                            <td class="formTitle">所在城市</td>
                            <td class="formValue">
                                <select id="F_CityId" name="F_CityId" class="form-control" onchange="ChangeCityData()">
                                    <option value="">==请选择城市==</option>
                                </select>
                            </td>
                            <td class="formTitle">行政区域</td>
                            <td class="formValue">
                                <select id="F_AreaId" name="F_AreaId" class="form-control">
                                    <option value="">==请选择行政区域==</option>
                                </select>
                            </td>
                            <td class="formTitle">公司地址</td>
                            <td class="formValue">
                                <input type="text" id="F_Address" name="F_Address" class="form-control" placeholder="请输入公司地址" />
                            </td>
                        </tr>
                        <tr>
                           
                            <td class="formTitle">所属行业<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <select id="F_IndustryId" name="F_IndustryId" class="form-control">
                                    <option value="">==请选择行业==</option>
                                </select>
                            </td>
                            <td class="formTitle"></td>
                            <td class="formValue">                               
                            </td>
                            <td class="formTitle"></td>
                            <td class="formValue">                                
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="6" class="interval">客户需求信息</td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">需求来源</td>
                            <td class="formValue">
                                <select id="F_Source" name="F_Source" class="form-control required">
                                    <option value="">==请选择需求来源==</option>
                                    <option value="0">400电话</option>
                                    <option value="1">销售自拓</option>
                                    <option value="2">网站订单</option>
                                    <option value="3">小程序订单</option>
                                    <option value="4">App订单</option>
                                </select>
                            </td>
                            <td class="formTitle">所属行业<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <select id="F_ZkIndustryId" name="F_ZkIndustryId" class="form-control">
                                    <option value="">==请选择行业==</option>
                                </select>
                            </td>
                            <td class="formTitle">活动主题<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <input type="text" id="F_ActivityTheme" name="F_ActivityTheme" class="form-control required" placeholder="请输入活动主题" />
                            </td>                                                      
                        </tr>
                        <tr>
                            <td class="formTitle">活动类型<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <select id="F_ActivityType" name="F_ActivityType" class="form-control required select2-container select2-container--default select2-container--open ">
                                    <option value="">==请选择活动类型==</option>
                                </select>
                            </td>  
                            <td class="formTitle">搭建日期</td>
                            <td class="formValue">
                                <input type="text" id="F_BuildDate" name="F_BuildDate" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="请输入活动搭建日期" />
                            </td>
                            <td class="formTitle">活动开始时间<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <input type="text" id="F_ActivityStartDate" name="F_ActivityStartDate" class="form-control input-wdatepicker required" onfocus="WdatePicker()" placeholder="请输入活动开始时间" />
                            </td>
                                                        
                        </tr>
                        <tr>
                            <td class="formTitle">活动结束时间<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <input type="text" id="F_ActivityEndDate" name="F_ActivityEndDate" class="form-control input-wdatepicker required" onfocus="WdatePicker()" placeholder="请输入活动结束时间" />
                            </td>
                            <td class="formTitle">预算金额<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <input type="text" id="F_DemandCash" name="F_DemandCash" class="form-control required number" placeholder="请输入预算金额" />
                            </td>
                            <td class="formTitle">活动城市</td>
                            <td class="formValue">
                                <select id="F_ActivityCityId" name="F_ActivityCityId" class="form-control">                                   
                                </select>
                            </td>
                                                                                  
                        </tr>
                        <tr>
                            <td class="formTitle">场地类型<span style="color:#d9534f;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <select id="F_SiteType" name="F_SiteType" class="form-control required">                                   
                                </select>
                            </td> 
                            <td class="formTitle">活动人数</td>
                            <td class="formValue">
                                <input type="text" id="F_PersionNumber" name="F_PersionNumber" class="form-control number" placeholder="请输入活动人数" />
                            </td> 
                            <td class="formTitle">场地面积(㎡)</td>
                            <td class="formValue">
                                <input type="text" id="F_SiteArea" name="F_SiteArea" class="form-control number" placeholder="请输入场地面积" />
                            </td>
                                                                                
                        </tr>
                        <tr>
                            <td class="formTitle">层高</td>
                            <td class="formValue">
                                <input type="text" id="F_Height" name="F_Height" class="form-control number" placeholder="请输入层高" />
                            </td>
                            <td class="formTitle"></td>
                            <td class="formValue"></td> 
                            <td class="formTitle"></td>
                            <td class="formValue"></td> 
                        </tr>
                        <tr>
                            <td class="formTitle">意向场地</td>
                            <td class="formValue" colspan="5">
                                <textarea rows="2" id="F_Intention" name="F_Intention" class="form-control" placeholder="请输入意向场地" style="width:99%;"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td class="formTitle">备注</td>
                            <td class="formValue" colspan="5">
                                <textarea rows="3" id="F_Note" name="F_Note" class="form-control" placeholder="请输入备注信息" style="width:99%;"></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="6" class="interval">品牌项目组信息</td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">直客名称</td>
                            <td class="formValue">
                                <div class="input-group" style="width:100%;">
                                    <input type="text" id="F_MappingId" class="form-control" placeholder="请输入直客名称" />
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                    <input type="hidden" name="hd_F_MappingId" id="hd_F_MappingId" value="" />
                                </div>
                            </td>                            
                            <td class="formTitle">品牌名称</td>
                            <td class="formValue">
                                <div class="input-group" style="width:100%;">
                                    <input type="text" id="F_BrandId" class="form-control" placeholder="请输入品牌名称" />
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                    <input type="hidden" name="hd_F_BrandId" id="hd_F_BrandId" value="" />
                                </div>
                            </td> 
                            <td class="formTitle">所属项目组</td>
                            <td class="formValue">
                                <div class="input-group" style="width:100%;">
                                    <input type="text" id="F_ProjectId" class="form-control" placeholder="请输入项目组" />
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                    <input type="hidden" name="hd_F_ProjectId" id="hd_F_ProjectId" value="" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            
                            <td class="formTitle">联系人<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <div class="input-group" style="width:100%;" id="isF_Contact">
                                    <input type="text" id="F_Contact" name="F_Contact" class="form-control required" placeholder="请输入联系人" />
                                    <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                                    <input type="hidden" name="hd_F_Contact" id="hd_F_Contact" value="" />
                                </div>
                            </td>
                            <td class="formTitle">所属部门</td>
                            <td class="formValue">
                                <select id="F_DepartmentId" name="F_DepartmentId" class="form-control">
                                    <option value="">==请选择部门==</option>
                                </select>
                            </td>
                            <td class="formTitle">所属职位</td>
                            <td class="formValue">
                                <select id="F_PositionId" name="F_PositionId" class="form-control">
                                    <option value="">==请选择职位==</option>
                                </select>
                            </td>
                        </tr>
                        <tr>                            
                            <td class="formTitle">性别</td>
                            <td class="formValue">
                                <input type="radio" name="F_Sex" value="1" />男<input type="radio" name="F_Sex" value="0" />女
                            </td>
                            <td class="formTitle">手机号码<span style="color:red;font-weight:bold;font-size:14px;">*</span></td>
                            <td class="formValue">
                                <input type="text" id="F_Phone" name="F_Phone" class="form-control required isMobile" placeholder="请输入手机号" />
                            </td>  
                            <td class="formTitle">公司座机</td>
                            <td class="formValue">
                                <input type="text" id="F_Telephone" name="F_Telephone" class="form-control isPhone" placeholder="请输入公司座机" />
                            </td>
                        </tr>
                        <tr>                            
                            <td class="formTitle">Email</td>
                            <td class="formValue">
                                <input type="text" id="F_Mail" name="F_Mail" class="form-control email" placeholder="请输入Email" />
                            </td>
                            <td class="formTitle"></td>
                            <td class="formValue"></td> 
                            <td class="formTitle"></td>
                            <td class="formValue"></td> 
                        </tr>
                    </table>
                </td>
            </tr>      
            
            <tr>
                <td colspan="6" class="interval">跟进人备注</td>
            </tr>
            <tr>
                <td colspan="6">
                    <table class="Table">
                        <tr>
                            <td class="formTitle">需求单状态变更</td>
                            <td class="formValue" colspan="5">
                                <input type="radio" name="F_State" value="0" />需求单 <input type="radio" name="F_State" value="1" />有效需求单 <input type="radio" name="F_State" value="2" onclick="ChangeFState()" />无效
                            </td>
                        </tr>
                        <tr id="tr_reason" style="display:none;">
                            <td class="formTitle" style="color:red;">关闭理由*</td>
                            <td class="formValue" colspan="5">
                                <input type="radio" name="F_CloseReason" value="1" />客户不提供活动详细信息
                                <input type="radio" name="F_CloseReason" value="2" />联系不到客户
                                <input type="radio" name="F_CloseReason" value="3" />预算太低
                                <input type="radio" name="F_CloseReason" value="4" />客户选择其他场地
                                <input type="radio" name="F_CloseReason" value="5" />无场地推荐
                                <input type="radio" name="F_CloseReason" value="6" />比稿失败
                                <input type="radio" name="F_CloseReason" value="7" />客户跳单
                                <input type="radio" name="F_CloseReason" value="8" />活动取消 
                                <input type="radio" name="F_CloseReason" value="9" />撞单 
                                <input type="radio" name="F_CloseReason" value="10" />其他
                                <input type="radio" name="F_CloseReason" value="11" />重复数据
                            </td>                            
                        </tr>
                        <tr>
                            <td class="formTitle">反馈信息</td>
                            <td class="formValue" colspan="5">
                                <textarea rows="3" id="F_Mark" class="form-control" placeholder="请输入反馈信息" style="width:99%;"></textarea>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="6" class="interval">客户历史记录</td>
            </tr>
            <tr>
                <td colspan="6">
                    <div class="zdyGirdPanel">
                        <table id="gridList"></table>
                        <div id="gridPager"></div>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
